package day_2022_12_to_3.year2023;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2023/03/22 21:14
 **/
public class Day3_22_Num1626 {
    class Solution {
        public int bestTeamScore(int[] scores, int[] ages) {
            Integer[] index = new Integer[scores.length];
            for (int i = 0; i < ages.length; i++) {
                index[i] = i;
            }
            Arrays.sort(index, (a, b) -> {
                if (ages[a] == ages[b])
                    return scores[a] - scores[b];
                return ages[a] - ages[b];
            });
            int ans = scores[index[0]];
            int[] dp = new int[index.length];
            dp[0] = scores[index[0]];
            for (int i = 1; i < index.length; i++) {
                dp[i] = scores[index[i]];
                for (int j = 0; j < i; j++) {
                    if (scores[index[j]] <= scores[index[i]]) {
                        dp[i] = Math.max(dp[i], dp[j] + scores[index[i]]);
                    }
                }
                ans = Math.max(ans, dp[i]);
            }
            return ans;
        }
    }
}